package jfm.demo.firstserver;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@Controller
public class FirstHelloController {

    @Autowired
    private DiscoveryClient discoveryClient;

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/")
    @ResponseBody
    public String hello() {
//        List<String> services = discoveryClient.getServices();
//        for (String s : services) {
//            System.out.println(s);
//        }
        List<ServiceInstance> instances = discoveryClient.getInstances("flow2");
        for (ServiceInstance si : instances) {
            System.out.println(si);
        }
//        return "hello";
        return restTemplate.getForObject("http://flow2/",String.class);
    }

}
